Trace Function

public function Trace(A) result(result)

function that calculates the trace of a square matrix

Arguments

Type IntentOptional Attributes Name
real(kind=dp), intent(in), DIMENSION(:, :) :: A

Return Value real(kind=dp)


Called by

proc~~trace~~CalledByGraph proc~trace Trace proc~faddeev_leverrier Faddeev_Leverrier proc~faddeev_leverrier->proc~trace

Source Code

    FUNCTION Trace(A) RESULT(result)
        REAL(dp), DIMENSION(:, :), INTENT(IN) :: A
        REAL(dp) :: result
        INTEGER :: i, N

        N = SIZE(A, 1)
        IF (SIZE(A, 2) /= N) STOP "Error: Matrix must be square."

        result = SUM([(A(i, i), i=1,N)])

    END FUNCTION Trace